package Servlet.User;

import DataBase.DataBase;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class changeUserInfoServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession HS = req.getSession();
        String name = req.getParameter("name");
        String location = req.getParameter("location");
        String username = HS.getAttribute("username").toString();

        DataBase.ChangeUserInfo(username,name,location);

        HS.setAttribute("location",location);
        HS.setAttribute("name",name);

        String confirm = req.getParameter("confirm");
        if(confirm == "1"){
            resp.getWriter().write("true");
        }
        else{
            resp.sendRedirect(req.getContextPath()+"/index.jsp");
        }

    }
}
